package com.nageoffer.shortlink.admin.config;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始自动填充：{}", metaObject);
        this.strictInsertFill(metaObject,"createTime", Date::new, Date.class);
        this.strictInsertFill(metaObject,"updateTime",  Date::new, Date.class);
        this.strictInsertFill(metaObject,"delFlag",()->0,Integer.class);

    }




    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始自动填充：{}",metaObject);
        this.strictUpdateFill(metaObject,"updateTime",Date::new,Date.class);

    }
}
